package com.cn.boot.spring.controller;

import com.cn.boot.spring.common.CommonResult;
import com.cn.boot.spring.entity.WxUserEntity;
import com.cn.boot.spring.service.IWxUserService;
import com.cn.boot.spring.vo.LoginParams;
import com.cn.boot.spring.vo.RegisterParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户控制层
 * @author LXJ
 * Created by lxj in 2021/01/30
 *
 */
@RestController
@Api("用户管理")
@RequestMapping("/wx/user")
public class WxUserController {
    @Autowired
    private IWxUserService iWxUserService;

    /**
     *登录
     */
    @PostMapping("/login")
    public CommonResult login(@RequestBody LoginParams loginParams){
        return iWxUserService.login(loginParams);
    }

    /**
     * 注册
     */
    @PostMapping("/register")
    public CommonResult register(@RequestBody RegisterParams registerParams){
        return iWxUserService.register(registerParams);
    }
    /**
     * 用户列表
     */
    @ApiOperation("用户列表")
    @GetMapping("/findAll")
    public CommonResult findAll(){
        return iWxUserService.findAll();
    }
    /**
     * 模糊查询
     */
    @ApiOperation("模糊查询")
    @PostMapping("/fuzzyFindAll")
    public CommonResult fuzzyFindAll(@RequestBody WxUserEntity wxUserEntity){
        return  iWxUserService.fuzzyFindAll(wxUserEntity);

    }
    /**
     * 分页查询
     */
    @ApiOperation("分页查询")
    @PostMapping("/pageFindAll")
    public CommonResult pageFindAll(@RequestParam Integer pageNum, @RequestParam Integer pageSize){
        return iWxUserService.pageFindAll(pageNum,pageSize);
    }

    /**
     * 根据id查找数据
     */
    @ApiOperation("根据id查找用户")
    @GetMapping("/findById")
    public CommonResult findById(@RequestParam Integer id){
        return iWxUserService.findById(id);
    }
    /**
     * 单条数据删除
     */
    @ApiOperation("单条数据删除")
    @Delete("/del")
    public CommonResult del(@RequestParam Integer id){
        return iWxUserService.del(id);
    }
    /**
     * 批量删除
     */
    @ApiOperation("批量删除")
    @Delete("/dels")
    public CommonResult dels(@RequestBody List<Integer> ids){
        return iWxUserService.dels(ids);
    }
    /**
     * 更新
     */
    @ApiOperation("更新数据")
    @PostMapping("/update")
    public CommonResult update(@RequestBody WxUserEntity wxUserEntity){
        return iWxUserService.update(wxUserEntity);
    }
}
